package my.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.alibaba.fastjson.JSONArray;

import af.spring.AfRestData;
import my.db.Student;
import my.tool.MybatisApi;

@Controller
public class AuthorityController {

	@GetMapping("authority")
	public String hello(Model model,HttpServletRequest request) {
		
		model.addAttribute("datas", IndexController.SimpleJS(request));
		return "Authority_Manager";
	}
	
	//保存教师的权限
	@PostMapping("author_saveTeacher.do")
	public Object saveTeacher(@RequestBody JSONArray jreqs) {
		
		MybatisApi.update("zhy.sesAuthority.clearTeacher", 0);
		for(int i = 0;i< jreqs.size();i++) {
			MybatisApi.update("zhy.sesAuthority.updateTeacher", jreqs.getInteger(i));
		}
		return new AfRestData("");
	}
	//保存学生的权限
		@PostMapping("author_saveStudent.do")
		public Object saveStudent(@RequestBody JSONArray jreqs) {
			MybatisApi.update("zhy.sesAuthority.clearStudent", 0);
			for(int i = 0;i< jreqs.size();i++) {
				MybatisApi.update("zhy.sesAuthority.updateStudent", jreqs.getInteger(i));
			}
			return new AfRestData("");
		}
}
